@file:Suppress("SpellCheckingInspection", "unused")

package com.example.base.aop.click

import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Pointcut
import org.aspectj.lang.reflect.MethodSignature

/**  短时间重复点击拦截切面处理类  **/
@Aspect
class RepeatClickAspect {

    companion object {
        private const val POINTCUT_METHOD = "execution(@com.example.base.aop.click.RepeatClick * *(..))"
    }

    @Pointcut(POINTCUT_METHOD)
    fun methodAnnotatedWithRepeatClick() {
    }

    @Around("methodAnnotatedWithRepeatClick()")
    fun aroundJoinPoint(joinPoint: ProceedingJoinPoint) {
        // get infomations
        val methodSignature = joinPoint.signature as MethodSignature
        val method = methodSignature.method
        val annotation = method.getAnnotation(RepeatClick::class.java)!!

        // 若为短时间内快速点击, 则不进行任何处理, 否则正常执行方法
        if (RepeatClickTool.isFastRepeatClick(annotation.value).not()) joinPoint.proceed()
    }

}